package nowcoder.day_48.day6;
/**
 * 字符串转整数
 */
public class Num2 {
    public int StrToInt(String str) {
        if (str.isEmpty())return 0;
        char[]arr = str.toCharArray();
        int temp = 1;
        if (arr[0] == '+'){
            arr[0] = '0';
            temp = 1;
        }else if (arr[0] == '-'){
            arr[0] = '0';
            temp = -1;
        }else {
            return 0;
        }
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            char ch = arr[i];
            if (Character.isDigit(ch)){
                sum = sum * 10 + (ch - '0');
            }else {
                sum = 0;
                break;
            }
        }
        return sum * temp;


    }
}
